<include file="Common@Backend/header" />
    <!-- page heading start-->
    <div class="page-heading">
        <h3>
            {$breadcrumb.A}
        </h3>
        <ul class="breadcrumb">
            <li>
                {$breadcrumb.M}
            </li>
            <li>
                {$breadcrumb.C}
            </li>
            <li class="active"> {$breadcrumb.A}  </li>
        </ul>
    </div>
    <!-- page heading end-->
    
    <!--body wrapper start-->
    <!-- {$goodslist} -->
    <!-- <?php print_r($goodslist);?> -->
    <div class="wrapper">
        <div class="row">
            <div class="col-lg-12">
                <section class="panel">
                    <form role="form" action="{$action}" method="post">
                        <header class="panel-heading">
                            添加商品
                        </header>
                        <div class="panel-body">
                            <div class="form-group">
                                <label for="goodsname">商品名</label>
                                <input type="text" name="goodsname" class="form-control" id="goodsname" placeholder="输入商品名" value="{$goodslist['goodsname']}">
                                <input type="hidden" value="{$goodslist['id']}" name="saveid">
                            </div>
                            <div class="form-group">
                                <label for="numgoods">货号</label>
                                <input type="text" name="numgoods" class="form-control" id="numgoods" placeholder="输入货号" value="{$goodslist['numgoods']}">
                            </div>
                            <div class="form-group">
                                <label for="keyword">关键词</label>
                                <input type="text" name="keyword" class="form-control" id="keyword" placeholder="输入关键词" value="{$goodslist['keyword']}">
                            </div>
                            <div class="form-group">
                                <label for="description">描述</label>
                                <input type="text" name="description" class="form-control" id="description" placeholder="输入描述" value="{$goodslist['description']}">
                            </div>
                            <div class="form-group">
                                <label for="stock">库存</label>
                                <input type="text" name="stock" class="form-control" id="stock" placeholder="输入库存" value="{$goodslist['stock']}">
                            </div>
                            <div class="form-group">
                                <label for="price">价格</label>
                                <input type="text" name="price" class="form-control" id="price" placeholder="输入价格" value="{$goodslist['price']}">
                            </div>

                            <div class="form-group">
                                <label for="category">分类</label>
                                <select class="form-control m-bot15" id="category" name="category[]" multiple="multiple" size="5">
                                    {$optionstr}
                                </select>
                            </div>
                            <!--*************photo***************-->
                             <div id="picker" class="col-md-2">添加</div>
                <!-- <form action="bannersave.php" id="articleForm" method="post"> -->
                   <!--  <div class="form-group">
                        <button class="btn btn-primary">保存</button>
                        <a href="index.php" class="btn btn-primary">返回</a>
                    </div> -->
                    <table class="table">
                        <thead>
                            <tr>
                                <th>图片</th>
                                <th>标题</th>
                                <th>链接</th>
                                <th>别名</th>

                                <th>操作</th>
                            </tr>
                        </thead>
                        
                        <tbody id="picBox">
                            <?php if(!empty($banner)){?>
                                <?php foreach ($banner as $key => $value) {?>
                                    <tr>
                                        <td><img src="__PUBLIC__/csf/upload/<?php echo $value['name'];?>?>" style="width: 100px;height: 100px;"><input type="hidden" name="banner[]" value="<?php echo $value['name'];?>"></td>
                                        <td><input type="text" name="title[]" value="<?php echo $value['title'];?>"></td>
                                        <td><input type="text" name="link[]" value="<?php echo $value['link'];?>"></td>
                                        <td><input type="text" name="alt[]" value="<?php echo $value['alt'];?>"></td>
                                        <td>
                                            <a href="#" class="delbtn">删除</a>
                                        </td>
                                    </tr>
                                <?php } ?>
                                
                            <?php } ?>
                        </tbody>
                    </table>
                <!-- </form> -->
            
                            <!--****************************-->
                            <div class="form-group" >
                                <div>商品详情</div>
                               <textarea  id="details" name="details" placeholder="输入商品详情">{$goodslist['details']}</textarea>
                            </div>
                            
                            <div class="form-group">
                                <label for="status">状态</label>
                                <select class="form-control m-bot15" id="status" name="status">
                                <if condition="$goodslist.status eq 1">
                                    <option value="1" selected="selected">启用</option>
                                    <option value="0">禁用</option>
                                <else/>
                                    <option value="1">启用</option>
                                    <option value="0" selected="selected">禁用</option>
                                </if>
                                </select>
                            </div>
                           

                            <button class="btn btn-success" type="submit">保存</button>
                            <button class="btn btn-danger"><a href="{$cancle}">取消</a></button>
                        </div>
                       
                    </form>
                </section>
            </div>
        </div>
    </div>
     <!--引入uedit编辑框-->
                <script type="text/javascript">
                     var ue = UE.getEditor('details',{
                        initialFrameWidth:1000,
                        initialFrameHeight:300,
                        autoHeightEnabled:false,
                        imagePathFormat:'/xinanshop/Public/photo',
                    });
                </script>

                  <!-- 引入上传文件工具 -->
                <script type="text/javascript">
                    var uploader = WebUploader.create({
                        // 选完文件后，是否自动上传。
                        auto: true,
                        // swf文件路径
                        swf: '__PUBLIC__/csf/webupload/Uploader.swf',
                        // 文件接收服务端。
                        server: '__PUBLIC__/csf/webupload/upfile.php',
                        // 选择文件的按钮。可选。
                        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                        pick: '#picker',
                        // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
                        resize: false,

                        // runtimeOrder:'flash',
                        // 只允许选择图片文件。
                        duplicate:true,
                        accept: {
                            title: 'Images',
                            extensions: 'gif,jpg,jpeg,bmp,png',
                            mimeTypes: 'image/jpg,image/jpeg,image/png',
                        }
                    });
                    //上传成功事件
                    uploader.on( 'uploadSuccess', function(file,response) {
                        if(response._raw!='000'){
                            // $('#sitelogo').val(response._raw);
                            var $tr = $(
                            '<tr><td id="' + file.id + '">' +
                                '<img>' +
                                '<input id="' + file.id + 'img" type="hidden" name="banner[]" value="'+response._raw+'"></td><td><input type="text" name="title[]"></td><td><input type="text" name="link[]"></td></td><td><input type="text" name="alt[]"></td><td><a href="#" class="delbtn">删除</a></td>' +
                            '</tr>'
                            ),
                            $img = $tr.find('img');
                            $('#picBox').append( $tr );
                            //生成缩略图
                            uploader.makeThumb( file, function( error, src ) {
                                if ( error ) {
                                    $img.replaceWith('<span>不能预览</span>');
                                    return;
                                }

                                $img.attr( 'src', src );
                            }, 100, 100 );
                        }
                        
                    });
                    //上传失败事件
                    uploader.on( 'uploadError', function( file ) {
                        var $li = $( '#'+file.id ),
                            $error = $li.find('div.error');

                        // 避免重复创建
                        if ( !$error.length ) {
                            $error = $('<div class="error"></div>').appendTo( $li );
                        }

                        $error.text('上传失败');
                    });
                </script>
                <!-- 动态绑定删除按钮 -->
                <script type="text/javascript">
                    $('#picBox').on('click','.delbtn',function(){
                        $(this).parent().parent().remove();
                        return false;
                    });
                </script>
           
    <!--body wrapper end-->
<include file="Common@Backend/footer" />